/**
 * Copyright &copy; 2015-2020 <a href="http://www.easyhis.com/">easyhis</a> All rights reserved.
 */
package com.easy.dfcapi.entity;

import com.easy.common.utils.IdGen;
import com.easy.common.utils.excel.annotation.ExcelField;
import com.easy.core.persistence.BaseEntity;
import com.easy.modules.sys.entity.Office;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 用户表Entity
 * @author waylen chi
 * @version 2018-01-02
 */
public class ApiUser extends BaseEntity<ApiUser> {
	
	private static final long serialVersionUID = 1L;
	private String id;		// user_uuid
	private Integer userId;		// 编号
	private Integer companyId;		// 归属公司
	private Office office;		// 归属部门
	private String loginName;		// 登录名
	private String password;		// 密码
	private String userNo;		// 工号
	private String userName;		// 姓名
	private String userNick;		// 用户呢称
	private String email;		// 邮箱
	private Integer sex;		// 性别
	private Date birthday;		// 生日
	private String phone;		// 电话
	private String mobile;		// 手机
	private Integer avatar;		// 用户头像
	private String avatarUrl;		// 用户头像
	private Integer userType;		// 用户类型
	private String loginIp;		// 最后登陆IP
	private Date loginTime;		// 最后登陆时间
	private String loginFlag;		// 是否可登录
	private ApiUser createBy;		// 创建者
	private Integer introId;		// 推荐人
	private String froms;		// 注册来源pc:电脑,mobile:手机,app:应用
	private Date createTime;		// 注册时间
	private ApiUser updateBy;		// 更新者
	private Date updateTime;		// 更新时间
	private String remarks;		// 备注信息
	private Integer delFlag;		// 删除标记
	private String qrcode;		// 二维码
	private String sign;		// 个性签名
	private Integer isRealName;		// 是否实名
	private Integer storeId;		// 默认的店铺ID
	
	public ApiUser() {
		super();
	}

	public ApiUser(Integer userId){
		this.userId = userId;
	}

	@NotNull(message="编号不能为空")
	@ExcelField(title="编号", fieldType=ApiUser.class, value=".userName", align=2, sort=0)
	@JsonIgnore
	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	
	@ExcelField(title="user_uuid", align=2, sort=1)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@ExcelField(title="归属公司", align=2, sort=2)
	public Integer getCompanyId() {
		return companyId;
	}

	public void setCompanyId(Integer companyId) {
		this.companyId = companyId;
	}
	
	@ExcelField(title="归属部门", fieldType=Office.class, value=".officename", align=2, sort=3)
	public Office getOffice() {
		return this.office;
	}

	public void setOffice(Office office) {
		this.office = office;
	}
	
	@ExcelField(title="登录名", align=2, sort=4)
	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	
	@ExcelField(title="密码", align=2, sort=5)
	@JsonIgnore
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	@ExcelField(title="工号", align=2, sort=6)
	public String getUserNo() {
		return userNo;
	}

	public void setUserNo(String userNo) {
		this.userNo = userNo;
	}
	
	@ExcelField(title="姓名", align=2, sort=7)
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserNick() {
		return userNick;
	}

	public void setUserNick(String userNick) {
		this.userNick = userNick;
	}

	@ExcelField(title="邮箱", align=2, sort=8)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	@ExcelField(title="性别", align=2, sort=9)
	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@ExcelField(title="生日", align=2, sort=10)
	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	
	@ExcelField(title="电话", align=2, sort=11)
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	@ExcelField(title="手机", align=2, sort=12)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@ExcelField(title="用户头像", align=2, sort=13)
	public Integer getAvatar() {
		//if(avatar ==null)return "/common/images/flat-avatar.png";
		return avatar;
	}

	public void setAvatar(Integer avatar) {
		this.avatar = avatar;
	}

	public String getAvatarUrl() {
		return avatarUrl;
	}

	public void setAvatarUrl(String avatarUrl) {
		this.avatarUrl = avatarUrl;
	}

	@NotNull(message="用户类型不能为空")
	@ExcelField(title="用户类型", align=2, sort=14)
	public Integer getUserType() {
		return userType;
	}

	public void setUserType(Integer userType) {
		this.userType = userType;
	}
	
	@ExcelField(title="最后登陆IP", align=2, sort=15)
	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@ExcelField(title="最后登陆时间", align=2, sort=16)
	public Date getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}
	
	@ExcelField(title="是否可登录", align=2, sort=17)
	public String getLoginFlag() {
		return loginFlag;
	}

	public void setLoginFlag(String loginFlag) {
		this.loginFlag = loginFlag;
	}
	
	@ExcelField(title="创建者", align=2, sort=18)
	public ApiUser getCreateBy() {
		return createBy;
	}

	public void setCreateBy(ApiUser createBy) {
		this.createBy = createBy;
	}
	
	@ExcelField(title="推荐人", align=2, sort=19)
	public Integer getIntroId() {
		return introId;
	}

	public void setIntroId(Integer introId) {
		this.introId = introId;
	}
	
	@ExcelField(title="注册来源pc:电脑,mobile:手机,app:应用", align=2, sort=20)
	public String getFroms() {
		return froms;
	}

	public void setFroms(String froms) {
		this.froms = froms;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@ExcelField(title="注册时间", align=2, sort=21)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@ExcelField(title="更新者", align=2, sort=22)
	public ApiUser getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(ApiUser updateBy) {
		this.updateBy = updateBy;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@ExcelField(title="更新时间", align=2, sort=23)
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	@ExcelField(title="备注信息", align=2, sort=24)
	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	@ExcelField(title="删除标记", dictType="del_flag", align=2, sort=25)
	@JsonIgnore
	public Integer getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(Integer delFlag) {
		this.delFlag = delFlag;
	}
	
	@ExcelField(title="二维码", align=2, sort=26)
	public String getQrcode() {
		return qrcode;
	}

	public void setQrcode(String qrcode) {
		this.qrcode = qrcode;
	}
	
	@ExcelField(title="个性签名", align=2, sort=27)
	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}
	
	@ExcelField(title="是否实名", align=2, sort=28)
	public Integer getIsRealName() {
		if(isRealName == null) return 0;
		return isRealName;
	}

	public void setIsRealName(Integer isRealName) {
		this.isRealName = isRealName;
	}
	
	@ExcelField(title="默认的店铺ID", align=2, sort=29)
	public Integer getStoreId() {
		return storeId;
	}

	public void setStoreId(Integer storeId) {
		this.storeId = storeId;
	}


	/**
	 * 插入之前执行方法，需要手动调用
	 */
	public void preInsert(){
		this.id = IdGen.uuid();

		this.updateTime = new Date();
		this.createTime = this.updateTime;
	}

	/**
	 * 更新之前执行方法，需要手动调用
	 */
	public void preUpdate(){
		this.updateTime = new Date();
	}
	/**
	 * 插入之前执行方法，需要手动调用
	 */
	public void preInsert(Date now){
		this.id = IdGen.uuid();

		this.updateTime = now;
		this.createTime = this.updateTime;
	}

	/**
	 * 更新之前执行方法，需要手动调用
	 */
	public void preUpdate(Date now){
		this.updateTime = now;
	}

}